package com.hyphenate.easeui.widget.chatrow;

import android.content.Context;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.easeui.R;
import com.hyphenate.exceptions.HyphenateException;

/**
 * Created by Administrator on 2017/11/2.
 */

public class EaseChatRowTransfer extends EaseChatRow {

    private TextView mTv_cash;
    private TextView mTv_balance;

    public EaseChatRowTransfer(Context context, EMMessage message, int position, BaseAdapter adapter) {
        super(context, message, position, adapter);
    }

    @Override
    protected void onInflateView() {
        inflater.inflate(message.direct() == EMMessage.Direct.RECEIVE ?
                R.layout.ease_row_received_transfer : R.layout.ease_row_sent_transfer, this);
    }

    @Override
    protected void onFindViewById() {
        mTv_cash = (TextView) findViewById(R.id.tv_cash);
//        mTv_balance.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(context, MyWalletActivity.class);
//                activity.startActivity(intent);
//            }
//        });
    }

    @Override
    protected void onSetUpView() {
        try {
            String transfer_amount = message.getStringAttribute("transferAmount");
            mTv_cash.setText(transfer_amount + "元");
        } catch (HyphenateException e) {
            e.printStackTrace();
        }
        // handle sending message
        if (message.direct() == EMMessage.Direct.SEND) {
            setMessageSendCallback();
            switch (message.status()) {
                case CREATE:
                    progressBar.setVisibility(View.GONE);
                    statusView.setVisibility(View.VISIBLE);
                    break;
                case SUCCESS:
                    progressBar.setVisibility(View.GONE);
                    statusView.setVisibility(View.GONE);
                    break;
                case FAIL:
                    progressBar.setVisibility(View.GONE);
                    statusView.setVisibility(View.VISIBLE);
                    break;
                case INPROGRESS:
                    progressBar.setVisibility(View.VISIBLE);
                    statusView.setVisibility(View.GONE);
                    break;
                default:
                    break;
            }
        } else {
            if (!message.isAcked() && message.getChatType() == EMMessage.ChatType.Chat) {
                try {
                    EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
                } catch (HyphenateException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    protected void onUpdateView() {
        adapter.notifyDataSetChanged();
    }

    //点击事件
    @Override
    protected void onBubbleClick() {


    }


}
